﻿@{
    Layout = null;
    ViewBag.Title = "标段选择弹出框";
}
<div class="pageContent" layouth="38">
    <form method="post" id="from_unit" action="demo/common/ajaxDone.html" class="pageForm required-validate" onsubmit="return validateCallback(this,dialogAjaxDone)">
        <ul id="project_unit_zTree" class="ztree">
        </ul>
    </form>
</div>
<div class="formBar">
    <ul>
        <li>
            <button type="button" class="btn btn-success btn-sm" onclick="unitSel()">
                选择</button>
        </li>
        <li>
            <button type="button" class="close btn btn-default btn-sm">
                取消</button>
        </li>
    </ul>
</div>
<script type="text/javascript">
    var project_unit_zTree;
    var setting = {
        treeObjId: "project_unit_zTree",
        isSimpleData: true,              //数据是否采用简单 Array 格式，默认false
        treeNodeKey: "id",               //在isSimpleData格式下，当前节点id属性
        treeNodeParentKey: "pId",        //在isSimpleData格式下，当前节点的父节点id属性
        showLine: true,                  //是否显示节点间的连线
        checkable: true,                 //每个节点上是否显示 CheckBox
        checkStyle: "radio",   //多选 checkbox   单选 radio
        callback: {
            nodeCreated: project_unit_zTree_creat    //这是节点生成时的回调函数
        }
    };
    function project_unit_zTree_creat(event, treeId, treeNode) {
        var section = $("#TheBcdProjectInfo_P_Section").val();
        if (section.indexOf(treeNode.id) >= 0 && treeNode.pId != null) {
            treeNode.checked = true;
            project_unit_zTree.updateNode(treeNode, true);
        }
    }
    $(function () {
        var ac = $("#input_action").val();
        $.getJSON(
           "/CompletionMaterials/ProjectSegment/" + ac,
           function (data) {
               project_unit_zTree = $("#project_unit_zTree").zTree(setting, data);
               project_unit_zTree.expandAll(true);
           });
    });

    function unitSel() {
        var unitCodes = "";
        var unitName = "";
        var nodes = project_unit_zTree.getCheckedNodes(true);
        for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].pId != null) {
                unitCodes += nodes[i].id + ",";
                unitName += nodes[i].name.replace("(" + nodes[i].id + ")", "") + ",";
            }
        }
        if (unitCodes != "")
            unitCodes = unitCodes.substring(0, unitCodes.length - 1);
        if (unitName != "")
            unitName = unitName.substring(0, unitName.length - 1);
        $("#TheBcdProjectInfo_P_Section").val(unitCodes);
        $("#TheBcdProjectInfo_P_Unit").val(unitName);
        $.bringBack();

    }
</script>
